import 'package:flutter/material.dart';
import 'package:shen_nai/entity/device_entity.dart';

//实时数据头部界面
class RealDataHeadView extends StatefulWidget {
  RealDataHeadView(this._entity, {Key? key}) : super(key: key);

  DeviceEntity _entity;

  @override
  State<RealDataHeadView> createState() => _RealDataHeadViewState();
}

class _RealDataHeadViewState extends State<RealDataHeadView> {
  bool isExpaned = true;

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Container(
          height: 36,
          margin: const EdgeInsets.symmetric(horizontal: 15),
          alignment: Alignment.centerLeft,
          decoration: BoxDecoration(
              borderRadius: isExpaned
                  ? const BorderRadius.vertical(top: Radius.circular(5))
                  : const BorderRadius.all(Radius.circular(5)),
              color: isExpaned
                  ? const Color(0xff3486F7)
                  : const Color(0xff3486F7).withOpacity(0.23)),
          child: InkWell(
            onTap: () {
              setState(() {
                isExpaned = !isExpaned;
              });
            },
            child: Row(
              children: [
                const SizedBox(
                  width: 11,
                ),
                Expanded(
                  child: Text(
                    '${widget._entity.name}',
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                    style: const TextStyle(color: Colors.white, fontSize: 16),
                  ),
                ),
                const SizedBox(
                  width: 11,
                ),
                Text(isExpaned ? '收起' : '展开',
                    style: const TextStyle(
                      color: Colors.white,
                    )),
                const SizedBox(
                  width: 3,
                ),
                Image.asset(
                  isExpaned ? 'assets/images/up.png' : 'assets/images/down.png',
                  width: 12,
                ),
                const SizedBox(
                  width: 10,
                )
              ],
            ),
          ),
        ),
        !isExpaned ? const SizedBox() : getExpandView(),
        Container(
          height: 40,
          margin: const EdgeInsets.only(top: 10, left: 15, right: 15),
          padding: const EdgeInsets.symmetric(horizontal: 10),
          decoration: BoxDecoration(
              color: const Color(0xff1E314D),
              borderRadius: BorderRadius.circular(6)),
          child: Row(children: [
            Expanded(
                child: Row(
              children: [
                const Text(
                  'A累计时间',
                  style: TextStyle(color: Colors.white, fontSize: 13),
                ),
                const SizedBox(
                  width: 5,
                ),
                Text(
                  widget._entity.time1!,
                  maxLines: 1,
                  overflow: TextOverflow.ellipsis,
                  style: const TextStyle(
                      color: Color(0xff04edf1),
                      fontSize: 18,
                      fontFamily: 'ShuMaGuan'),
                )
              ],
            )),
            Expanded(
                child: Row(
              children: [
                const Text(
                  'A累计电量',
                  style: TextStyle(color: Colors.white, fontSize: 13),
                ),
                const SizedBox(
                  width: 5,
                ),
                Text(
                  widget._entity.power1!,
                  maxLines: 1,
                  overflow: TextOverflow.ellipsis,
                  style: const TextStyle(
                      color: Color(0xff04edf1),
                      fontSize: 18,
                      fontFamily: 'ShuMaGuan'),
                )
              ],
            ))
          ]),
        ),
        Container(
          height: 40,
          margin: const EdgeInsets.only(top: 10, left: 15, right: 15),
          padding: const EdgeInsets.symmetric(horizontal: 10),
          decoration: BoxDecoration(
              color: const Color(0xff1E314D),
              borderRadius: BorderRadius.circular(6)),
          child: Row(children: [
            Expanded(
                child: Row(
              children: [
                const Text(
                  'B累计时间',
                  maxLines: 1,
                  overflow: TextOverflow.ellipsis,
                  style: TextStyle(color: Colors.white, fontSize: 13),
                ),
                const SizedBox(
                  width: 5,
                ),
                Text(
                  widget._entity.time2!,
                  style: const TextStyle(
                      color: Color(0xff04edf1),
                      fontSize: 18,
                      fontFamily: 'ShuMaGuan'),
                )
              ],
            )),
            Expanded(
                child: Row(
              children: [
                const Text(
                  'B累计电量',
                  maxLines: 1,
                  overflow: TextOverflow.ellipsis,
                  style: TextStyle(color: Colors.white, fontSize: 13),
                ),
                const SizedBox(
                  width: 5,
                ),
                Text(
                  widget._entity.power2!,
                  maxLines: 1,
                  overflow: TextOverflow.ellipsis,
                  style: const TextStyle(
                      color: Color(0xff04edf1),
                      fontSize: 18,
                      fontFamily: 'ShuMaGuan'),
                )
              ],
            ))
          ]),
        ),
      ],
    );
  }
  //获取展开界面
  Widget getExpandView() {
    return Container(
      width: MediaQuery.of(context).size.width - 30,
      decoration: BoxDecoration(
          border: Border.all(color: const Color(0xff4D4D4D), width: 1),
          borderRadius:
              const BorderRadius.vertical(bottom: Radius.circular(5))),
      child: Column(
        children: [
          SizedBox(
            height: 12,
          ),
          Row(
            children: [
              SizedBox(
                width: 12,
              ),
              Expanded(
                  child: Text(
                '单位：${widget._entity.name}',
                maxLines: 1,
                overflow: TextOverflow.ellipsis,
                style: const TextStyle(color: Colors.white, fontSize: 12),
              )),
              SizedBox(
                width: 12,
              )
            ],
          ),
          SizedBox(
            height: 12,
          ),
          Row(
            children: [
              SizedBox(
                width: 12,
              ),
              Expanded(
                  flex: 3,
                  child: Text(
                    '合同编号：${widget._entity.contractNO}',
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                    style: const TextStyle(color: Colors.white, fontSize: 12),
                  )),
              Expanded(
                  flex: 2,
                  child: Text(
                    '设备交付日：${widget._entity.endDate}',
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                    style: const TextStyle(color: Colors.white, fontSize: 12),
                  )),
              SizedBox(
                width: 12,
              )
            ],
          ),
          SizedBox(
            height: 12,
          ),
          Row(
            children: [
              SizedBox(
                width: 12,
              ),
              Expanded(
                  child: Text(
                '质保完成日：${widget._entity.qualityDate}',
                maxLines: 1,
                overflow: TextOverflow.ellipsis,
                style: const TextStyle(color: Colors.white, fontSize: 12),
              )),
              SizedBox(
                width: 12,
              )
            ],
          ),
          SizedBox(
            height: 12,
          ),
        ],
      ),
    );
  }
}
